package com.china08.yxyapi.api.manage.edu.platform.slider;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.platform.YxyHomeSlider;
import com.china08.yxyapi.repository.mg.YxyHomeSliderRepository;

import io.swagger.annotations.ApiOperation;

/**
 * 教育局平台办公 焦点图管理 搜索
 * 
 */
@CrossOrigin
@RestController
public class SliderSrhController extends YxyApiBaseController {

    @Autowired
    private YxyHomeSliderRepository yhsr;

    @ApiOperation(value = "教育局 焦点图列表")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/edu/platform/slider", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response) {
        String eduId = getProfile(request, response).getSchoolId();
        List<RespModel> respList = new ArrayList<SliderSrhController.RespModel>();
        List<YxyHomeSlider> list = yhsr.findByEdbIdAndStatusOrderByOrderNumDesc(eduId, 0);
        for (YxyHomeSlider yxyHomeSlider : list) {
            RespModel model = new RespModel();
            model.id = yxyHomeSlider.getId();
            model.img = yxyHomeSlider.getImg();
            model.url = yxyHomeSlider.getUrl();
            model.orderNum = yxyHomeSlider.getOrderNum();
            respList.add(model);
        }
        return respList;
    }

    protected static class RespModel {
        public String id;
        public String img;
        public String url;
        public Integer orderNum;
    }

}
